#ifndef __Relay_Control_H
#define __Relay_Control_H

#ifdef APM32E10X_HD
	#include "apm32e10x_gpio.h"
	#include "apm32e10x_rcm.h"
#elif defined AT32F403AVGT7
	#include "at32f403a_407_gpio.h"
	#include "at32f403a_407_crm.h"
#else
	#include "apm32f10x_gpio.h"
	#include "apm32f10x_rcm.h"
#endif

#include "BoardData.h"


// 复用功能开启 //
#if defined SQDri_EVSEB_7KW || defined SQDri_EVSEB_11KW
  #define Rly_IOMUX_RTC              RCM_APB2_PERIPH_AFIO  
  #define RCM_EnableMUXPeriphClock   RCM_EnableAPB2PeriphClock
#endif

// 继电器引脚 //
#if RlyPin_Ctrl_PWM_EN > 0
  #if defined SQDri_EVSEB_7KW || defined SQDri_EVSEB_11KW
		//引脚块1 = Relay_ON_OFF = 启动引脚 = PD13
		#define Rly_RTC             RCM_APB2_PERIPH_GPIOD
		#define Rly_PinPort         GPIOD
		#define Rly1_PinId          GPIO_PIN_13		
	#else
	  //引脚块1 = 接引脚块B
		#define Rly_RTC             RCM_APB2_PERIPH_GPIOB
		#define Rly_PinPort         GPIOB
		#define Rly1_PinId          GPIO_PIN_13 
	#endif
#else
  #ifdef SQDri_EVSEB_7KW
		//引脚块1 = Relay_ON_OFF = 启动引脚 = PA11
		#define Rly_RTC             RCM_APB2_PERIPH_GPIOA
		#define Rly_PinPort         GPIOA
		#define Rly1_PinId          GPIO_PIN_11

		#if Has_RlyPin_Maintaining > 0
		// 继电器维持引脚：Relay_Value脚: PA12
		#define Rly2_RTC             RCM_APB2_PERIPH_GPIOA
		#define Rly2_PinPort         GPIOA
		#define Rly2_PinId           GPIO_PIN_12
		#endif

	#elif defined SQDri_EVSEB_11KW
		//引脚块1 = 接引脚块B = 启动引脚 = PA11
		#define Rly_RTC             RCM_APB2_PERIPH_GPIOD
		#define Rly_PinPort         GPIOD
		#define Rly1_PinId          GPIO_PIN_13

		#if Has_RlyPin_Maintaining > 0
		// 继电器维持引脚：Relay_Value脚
		#define Rly2_RTC             RCM_APB2_PERIPH_GPIOA
		#define Rly2_PinPort         GPIOA
		#define Rly2_PinId           GPIO_PIN_12
		#endif

	#else
		//引脚块1 = 接引脚块B
		#define Rly_RTC             RCM_APB2_PERIPH_GPIOB
		#define Rly_PinPort         GPIOB
		#define Rly1_PinId          GPIO_PIN_13 

	#endif
#endif //RlyPin_Ctrl_PWM_EN > 0


void Rly_init(void);
void Rly_on(void);
void Rly_off(void);
#if Has_RlyPin_Maintaining > 0
void Rly_release_startup_Pin(void);
#endif

#endif


